/**
 * Copyright By Grandsoft Company Limited.  
 * 2013-6-13 上午11:30:05
 */
package com.glodon.ggzy.jypt.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.glodon.ggzy.core.utils.PageSearchModel;
import com.glodon.ggzy.fwpt.service.IJsgcProjectService;
import com.glodon.ggzy.vo.ProjectSubway;

/**
 * 
 * 招标人控制类
 * @author sunpf
 * @date 2013-6-12
 *
 */
@Controller
public class ZbrController {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private IJsgcProjectService jsgcProjectService;

	/**
	 * 首页
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/zbr_index")
	public String zbrIndex(Model model) {
		return "/jypt/zbr_index";
	}

	/**
	 * 企业资质
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/zbr_ent_qual")
	public String zbrEntQual(Model model) {
		return "/jypt/zbr_ent_qual";
	}

	/**
	 * 基本信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/zbr_base_info")
	public String zbrBaseInfo(Model model) {
		return "/jypt/zbr_base_info";
	}

	/**
	 * 项目进场登记
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/zbr_project_enter")
	public String projectEnterInfo(Model model) {
		return "/jypt/zbr_project_enter";
	}

	/**
	 * 我的招标项目
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/zbr_my_project")
	public String myProject(Model model) {
		return "/jypt/zbr_my_project";
	}

	/**
	 * 建设工程
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/get_zbr_project_enter")
	public void getProjectEnterInfo(Model model, int rows, int page, HttpServletResponse response) {
		PageSearchModel qm = new PageSearchModel();
		qm.setPageNo(page);
		qm.setPageSize(rows);
		/**
		Page queryPage = jsgcProjectService.queryPage(qm);
		List<JsgcProject> projectList = (List<JsgcProject>) queryPage.getResult();
		List<ProjectEnter> peList = new ArrayList<ProjectEnter>();
		ProjectEnter pe = null;
		for (JsgcProject project : projectList) {
			pe = new ProjectEnter();
			pe.setPackageType(project.getPrjType());
			pe.setBaseInfo("标段一:"+project.getPrjName()+"<br>标段二:"+project.getPrjName());
			pe.setProjectCode(project.getPrjNo());
			pe.setProjectName(project.getPrjName());
			pe.setApproveStatus(project.getPrjStatus());
			pe.setOperation("<a href='#'><font color=blue>查看</font></a>");
			peList.add(pe);
		}
		queryPage.setResult(peList);
		**/
		String jsonStr = "";
		try {
			//jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 建设工程
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/get_zbr_my_project")
	public void getMyProject(Model model, int rows, int page, String searchText, HttpServletResponse response) {
		PageSearchModel qm = new PageSearchModel();
		qm.setPageNo(page);
		qm.setPageSize(rows);
		if (StringUtils.isNotEmpty(searchText)) {
			try {
				String[] params = new String[1];
				params[0] = "%" + URLDecoder.decode(searchText, "UTF-8") + "%";
				qm.setParams(params);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		/**
		Page queryPage = jsgcProjectService.queryPage(qm);
		List<JsgcProject> projectList = (List<JsgcProject>) queryPage.getResult();
		List<MyProject> peList = new ArrayList<MyProject>();
		MyProject pe = null;
		for (JsgcProject project : projectList) {
			pe = new MyProject();
			pe.setPackageCode("JS2012323-1");
			pe.setBaseInfo("标段一:" + project.getPrjName() + "<br>标段二:" + project.getPrjName());
			pe.setProjectName(project.getPrjName());
			pe.setOperation("<a href='zbr_project_subway.do'><font color=blue>进入</font></a>");
			pe.setMessage(project.getPrjType());
			pe.setPackageStatus(project.getPrjStatus());
			peList.add(pe);
		}
		queryPage.setResult(peList);
		**/
		String jsonStr = "";
		try {
			//jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 项目地铁站
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/zbr_project_subway")
	public String redirectProjectSubway(Model model) {
		DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分");
		try {
			ProjectSubway way = new ProjectSubway(df.parse("2013年4月21日 09时21分"), df.parse("2013年4月30日 09时00分"), df.parse("2013年5月08日 09时00分"),
					df.parse("2013年5月15日 09时21分"), df.parse("2013年5月30日 09时00分"), "true", "报名家数少于三家", "备案通过", "未预约", "编辑中", "1");
			model.addAttribute("pway", way);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/jypt/zbr_project_subway";
	}

}
